﻿using System;
using System.Security.Cryptography;
using System.Diagnostics;
using System.Text;


namespace FillMyMug
{

    class ProtectedInformation
    {

        static byte[] saltString = { 1, 9, 8, 7, 6, 5 };

        private string _userName = "";
        private string _userPassword = "";

        
        public string userName{
            set{_userName = value;}
            get{return _userName;}
        }

        public string passWord { 
            set { _userPassword = value; } 
            get { return _userPassword; } 
        }

        private void retrieveData() {

            using (Microsoft.Win32.RegistryKey r = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("FillMyMug"))
            {
                _userName =(string) r.GetValue("userName");
                _userPassword = (string)r.GetValue("userPassword");
            }
        
        }
        private void storeData() {

            using (Microsoft.Win32.RegistryKey r = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("FillMyMug")) {

                r.SetValue("userName", ProtectedData.Protect((new UnicodeEncoding().GetBytes(_userName)), saltString, DataProtectionScope.CurrentUser));
                r.SetValue("userPassword", ProtectedData.Protect((new UnicodeEncoding().GetBytes(_userPassword)), saltString, DataProtectionScope.CurrentUser));
            }
        }


        public ProtectedInformation() {

            retrieveData();

        }
        ~ProtectedInformation() {
            storeData();
            
        }
        
        
    }
}